using Microsoft.Phone.Controls.Maps.AutomationPeers;
using System;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Media;
namespace Microsoft.Phone.Controls.Maps.Overlays
{
	[TemplatePart(Name = "Text1", Type = typeof(TextBlock)), TemplatePart(Name = "Text2", Type = typeof(TextBlock))]
	public class ShadowText : Overlay
	{
		internal const string Text1ElementName = "Text1";
		internal const string Text2ElementName = "Text2";
		private TextBlock text1;
		private TextBlock text2;
		public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(ShadowText), new PropertyMetadata(new PropertyChangedCallback(ShadowText.OnTextChanged)));
		public static readonly DependencyProperty ForegroundTopProperty = DependencyProperty.Register("ForegroundTop", typeof(Brush), typeof(ShadowText), new PropertyMetadata(new PropertyChangedCallback(ShadowText.OnTextChanged)));
		public static readonly DependencyProperty ForegroundBottomProperty = DependencyProperty.Register("ForegroundBottom", typeof(Brush), typeof(ShadowText), new PropertyMetadata(new PropertyChangedCallback(ShadowText.OnTextChanged)));
		private readonly Brush Black = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
		private readonly Brush White = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
		public string Text
		{
			get
			{
				return (string)base.GetValue(ShadowText.TextProperty);
			}
			set
			{
				base.SetValue(ShadowText.TextProperty, value);
			}
		}
		public Brush ForegroundTop
		{
			get
			{
				return (Brush)base.GetValue(ShadowText.ForegroundTopProperty);
			}
			set
			{
				base.SetValue(ShadowText.ForegroundTopProperty, value);
			}
		}
		public Brush ForegroundBottom
		{
			get
			{
				return (Brush)base.GetValue(ShadowText.ForegroundBottomProperty);
			}
			set
			{
				base.SetValue(ShadowText.ForegroundBottomProperty, value);
			}
		}
		public ShadowText()
		{
			base.set_DefaultStyleKey(typeof(ShadowText));
			this.text1 = new TextBlock();
			this.text2 = new TextBlock();
		}
		public void SetForegroundColorsForDarkBackground()
		{
			this.SetForegroundColors(this.White, this.Black);
		}
		public void SetForegroundColorsForLightBackground()
		{
			this.SetForegroundColors(this.Black, this.White);
		}
		public void SetForegroundColors(Brush top, Brush bottom)
		{
			this.ForegroundTop = top;
			this.ForegroundBottom = bottom;
		}
		private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			((ShadowText)d).OnTextChanged();
		}
		private void OnTextChanged()
		{
			this.text1.set_Text(this.Text);
			this.text2.set_Text(this.Text);
			if (this.ForegroundTop != null && this.ForegroundBottom != null)
			{
				this.text1.set_Foreground(this.ForegroundBottom);
				this.text2.set_Foreground(this.ForegroundTop);
			}
		}
		protected override AutomationPeer OnCreateAutomationPeer()
		{
			return new BaseAutomationPeer(this, "ShadowText");
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			this.text1 = (base.GetTemplateChild("Text1") as TextBlock);
			this.text2 = (base.GetTemplateChild("Text2") as TextBlock);
			this.OnTextChanged();
			base.FireTemplateApplied();
		}
	}
}
